package com.yang.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class ResponseResult<T> {

    // 状态码
    private String code;

    // 提示信息，如果有错误时，前端可以获取该字段进行提示
    private String msg;

    // 查询到的结果数据
    private T data;

    public static ResponseResult successResult() {
        return new ResponseResult("200", "调用成功", null);
    }

    public static ResponseResult successResult(Object data) {
        return new ResponseResult("200", "调用成功", data);
    }

    public static ResponseResult successResult(Object data, String msg) {
        return new ResponseResult("200", msg, data);
    }

    public static ResponseResult successResult(String code, String msg, Object data) {
        return new ResponseResult(code, msg, data);
    }

    public static ResponseResult failedResult(String message) {
        return new ResponseResult("400", message, null);
    }

    public static ResponseResult failedResult(String statusCode, String message) {
        return new ResponseResult(statusCode, message, null);
    }

    public ResponseResult() {
    }

    public ResponseResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

}